package com.haiqi.modules.map.service;

import com.github.pagehelper.PageInfo;
import com.haiqi.common.bean.PageBean;
import com.haiqi.common.persistence.dao.ServerPointMapper;
import com.haiqi.common.persistence.entity.ServerPoint;
import com.haiqi.common.utils.DateUtils;
import com.haiqi.common.utils.PageUtils;
import com.haiqi.common.utils.UUIDGenerator;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2017/7/5 0005.
 */
@Service
public class ServerPointService {
    @Autowired
    private ServerPointMapper serverPointMapper;


    public boolean save(ServerPoint serverPoint){
        boolean success = false;
        int i = 0;
        if(StringUtils.isNotEmpty(serverPoint.getId())){  //编辑
//            serverPointMapper.deleteByPrimaryKey(serverPoint.getId());
            serverPoint.setPublishtime(DateUtils.dateToString(new Date(),DateUtils.DATETIME_FORMAT));
            i = serverPointMapper.updateByPrimaryKeySelective(serverPoint);
        }else{  //添加
            serverPoint.setId(UUIDGenerator.getUUID());
            serverPoint.setPublishtime(DateUtils.dateToString(new Date(),DateUtils.DATETIME_FORMAT));
            i = serverPointMapper.insertSelective(serverPoint);
        }

        if(i > 0){
            success = true;
        }
        return success;
    }


    public boolean update(ServerPoint serverPoint){
        boolean success = false;
        int i = 0;
        if(StringUtils.isNotEmpty(serverPoint.getId())){
            i= serverPointMapper.updateByPrimaryKeySelective(serverPoint);
        }

        if(i > 0){
            success = true;
        }
        return success;
    }


    public boolean delete(ServerPoint serverPoint){
        boolean success = false;
        int i = serverPointMapper.deleteByPrimaryKey(serverPoint.getId());
        if(i > 0){
            success = true;
        }
        return success;
    }

    public List<ServerPoint> getDataList(ServerPoint serverPoint){
        List<ServerPoint> serverPoints= serverPointMapper.select(serverPoint);
        return serverPoints;
    }

    public PageInfo<ServerPoint> getDataList(ServerPoint serverPoint, PageBean page){
        PageUtils.generatePage(page);
        List<ServerPoint> dataList = serverPointMapper.select(serverPoint);
        PageInfo<ServerPoint> shipInfoList = new PageInfo<ServerPoint>(dataList);
        return shipInfoList;
    }

    public PageInfo<ServerPoint> selectServerPointCheck(ServerPoint serverPoint, PageBean page){
        PageUtils.generatePage(page);
        List<ServerPoint> dataList = serverPointMapper.selectServerPointCheck(serverPoint);
        PageInfo<ServerPoint> shipInfoList = new PageInfo<ServerPoint>(dataList);
        return shipInfoList;
    }

    public List<ServerPoint> selectCheck(ServerPoint serverPoint){
        List<ServerPoint> dataList = serverPointMapper.selectServerPointCheck(serverPoint);
        return dataList;
    }

    public ServerPoint selectByPrimaryKey(String id)
    {
        return serverPointMapper.selectByPrimaryKey(id);
    }
}
